package cn.kgc.jdbc.service;

import cn.kgc.jdbc.dao.ClazzDao;
import cn.kgc.jdbc.dao.ClazzDaoImpl;
import cn.kgc.jdbc.dao.StudentDao;
import cn.kgc.jdbc.dao.StudentDaoImpl;
import cn.kgc.jdbc.entity.Clazz;
import cn.kgc.jdbc.entity.Student;
import cn.kgc.jdbc.utils.Result;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/4/22
 */
public class StudentServiceImpl implements StudentService {
    private StudentDao studentDao = new StudentDaoImpl() ;
    private ClazzDao clazzDao = new ClazzDaoImpl();
    @Override
    public boolean addStudent(String stuName) {
        int line = studentDao.insertStudent(stuName);
        return line > 0 ;
    }

    @Override
    public boolean delStudent(int id) {
        int line = studentDao.delStudent(id);
        return line > 0 ;
    }

    @Override
    public boolean divideClazz(int stuNo, String clazzName) {

        //1.根据班级名称查询班级的id
        Clazz clazz = clazzDao.selectByName(clazzName);
        long clazzId = clazz.getId(); // 班级编号
        //2.根据学号更新学生的班级信息
        int line  = studentDao.updateStudent(stuNo,clazzId);
        return line >0;

    }

    @Override
    public List<Student> selectAll() {
        return  studentDao.selectAll();
    }
}
